unit uBaseCompThread;

interface

uses
  System.Classes, System.UITypes, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.Dialogs;

type
  TBaseCompThread = class(TThread)
  private
    ProgressBar: TProgressBar;
    StatusBar: TStatusBar;
    LoadExcelFileBtn: TButton;
    UpdateBtn: TButton;
    PageControl: TPageControl;
  protected
    PBStyle: TProgressBarStyle;
    StatusText: string;
    Enabled: Boolean;
    ErrorMessage: string;

    procedure SetProgressBarStyle;
    procedure SetStatusBarText;
    procedure ChangeControlAvailability;
    procedure ShowErrorDialog;
  public
    constructor Create(CreateSuspended: Boolean; ProgressBar: TProgressBar;
                       StatusBar: TStatusBar; PageControl: TPageControl;
                       LoadExcelFileBtn, UpdateBtn: TButton); overload;
  end;

implementation

// TBaseCompThread
// Базовый класс потока

constructor TBaseCompThread.Create(CreateSuspended: Boolean; ProgressBar: TProgressBar;
                                   StatusBar: TStatusBar; PageControl: TPageControl;
                                   LoadExcelFileBtn, UpdateBtn: TButton);
begin
  inherited Create(CreateSuspended);

  Self.ProgressBar := ProgressBar;
  Self.StatusBar := StatusBar;
  Self.LoadExcelFileBtn := LoadExcelFileBtn;
  Self.UpdateBtn := UpdateBtn;
  Self.PageControl := PageControl;
end;

procedure TBaseCompThread.ChangeControlAvailability;
begin
  // Изменение доступности элементов интерфейса через переменную Enabled
  Self.LoadExcelFileBtn.Enabled := Self.Enabled;
  Self.UpdateBtn.Enabled := Self.Enabled;
  Self.PageControl.Enabled := Self.Enabled;
end;

procedure TBaseCompThread.SetStatusBarText;
begin
  // Вывод текста в StatusBar
  StatusBar.Panels[0].Text := StatusText;
end;

procedure TBaseCompThread.SetProgressBarStyle;
begin
  // Изменение стиля ProgressBar
  ProgressBar.Style := PBStyle;
end;

procedure TBaseCompThread.ShowErrorDialog;
begin
  // Отправка сообщения с ошибкой
  MessageDlg(Self.ErrorMessage, mtError, [mbOK], 0);
end;

end.
